﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
</head>
<body>

<div class="container-fluid" style="margin-top: 20px">
    <#include "../common/top.ftl"/>

    <div class="row">
        <div class="col-lg-2">
            <#assign menu="systemDictionary"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-lg-10">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">字典目录管理</h1>
                </div>
            </div>
        <#-- 高级查询 -->
            <form class="form-inline" id="searchForm" action="/systemDictionary/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="pageSize" id="pageSize" value="20">
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>字典标题</th>
                    <th>字典编码</th>
                    <th>字典介绍</th>
                    <th>操作</th>
                </tr>
                <#list (ro.list)! as entity>
                    <tr>
                        <td>${(entity_index + 1)!}</td>
                        <td>${(entity.title)!}</td>
                        <td>${(entity.sn)!}</td>
                        <td>${(entity.intro)!}</td>
                        <td>
                            <a role="button" class="btn btn-info btn-xs inputBtn" data-json='${(entity.json)!}'>
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a role="button" data-url="/systemDictionary/delete.do?id=${(entity.id)!}"
                               class="btn btn-danger btn-xs deleteBtn">
                                <span class="glyphicon glyphicon-trash"></span> 删除
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>

        <#--分页-->
            <#include "../common/page.ftl" />
        </div>
    </div>
</div>

<#-- 字典目录编辑的模态框 -->
<div class="modal fade" id="systemDictionaryModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框的头部-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="systemDictionaryModal">编辑</h4>
            </div>
        <#--模态框的正文-->
            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionary/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-lg-4 control-label">字典标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入字典标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">字典编码：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="sn" placeholder="请输入字典编码">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">字典简介：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="intro" placeholder="请输入字典简介">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary systemDictionarySubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        //找到所有的inputBtn类绑定点击事件
        $(".inputBtn").click(function () {
            //1:先清空模态框数据
            $("#editForm input").val("");
            //2:尝试拿到当前按钮上的JSON数据
            //拿到到data-json
            var json = $(this).data("json"); //去当前对象上的自定义属性的数据
            //3:只有编辑按钮才要回显数据
            if (json) {
                //把数据回显到模态框中
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='title']").val(json.title);
                $("#editForm input[name='sn']").val(json.sn);
                $("#editForm input[name='intro']").val(json.intro);
            }
            //4:弹出模态框
            $("#systemDictionaryModal").modal("show");
        });

        //异步提交表单
        $(".systemDictionarySubmitBtn").click(function () {
            $("#editForm").ajaxSubmit(function (data) {
                if (data.success) {
                    msg("保存成功");
                } else {
                    msg(data.msg);
                }
            });
        });

    //  删除单条数据
        $(".deleteBtn").click(function () {
            var url = $(this).data("url");
            $.messager.confirm("提示","确定要删除这条数据吗?",function () {
               $.get(url,function (data) {
                  if(data.success){
                      msg("删除成功");
                  } else{
                      msg(data.msg);
                  }
               });

            });

        });



        //表单验证,---不生效
        $("#editForm").validate({
            rules:{
                title:{
                    required:true,
                    minlength:2
                },
                sn:{
                    required:true,
                    minlength:2
                },
                intro:{
                    required:true,
                    minlength:2
                }
            },
            messages:{
                title:{
                    required:"不能为空",
                    minlength:"不能少于两个字符"
                },
                sn:{
                    required:"不能为空",
                    minlength:"不能少于两个字符"
                },
                intro:{
                    required:"不能为空",
                    minlength:"不能少于两个字符"
                }
            }
        });


    });
</script>
</body>
</html>